package com.hellogood.yaohuo.client.common;

import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.events.RowEditorExitEvent;
import com.smartgwt.client.widgets.grid.events.RowEditorExitHandler;

public class CodeRowEditorExitHandler implements RowEditorExitHandler {

	private ListGrid listGrid;

	public CodeRowEditorExitHandler(ListGrid listGrid) {
		this.listGrid = listGrid;
	}

	@Override
	public void onRowEditorExit(RowEditorExitEvent event) {
		int row = listGrid.getEditRow();
		int pluCol = listGrid.getFieldNum("pluCode");
		int amountCol = listGrid.getFieldNum("amount");
		Object pluCode = listGrid.getEditedCell(row, pluCol);
		if (pluCode == null || pluCode.equals("")) {
			pluCode = listGrid.getEditValue(row, pluCol);
		}

		Object amount = listGrid.getEditedCell(row, amountCol);
		if (amount == null) {
			amount = listGrid.getEditValue(row, amountCol);
		}

		if ((pluCode != null && !pluCode.toString().equals("")) && (amount == null || amount.toString().equals("0"))) {
			event.cancel();
		}
	}

}
